from selenium import webdriver
from selenium.webdriver.common.by import By
import time

class Browser:
    # 初始化数据
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.url = ('https://ecshop.test2.shopex123.com')
        self.content ='欧莱雅'
        self.username = 'a1234'
        self.email = '148567@qq.com'
        self.password = 'aa123456'

    def home_search(self):
        # 打开网址ecshop
        self.driver.get(self.url)
        # 定位搜索框并输入要搜索的内容
        self.driver.find_element(By.ID,'keyword').send_keys(self.content)
        # 定位搜索按钮并点击
        self.driver.find_element(By.CLASS_NAME,'btn_search').click()

    def register(self):
        # 打开网址ecshop
        self.driver.get(self.url)
        # 定位免费注册按钮并点击
        self.driver.find_element(By.CLASS_NAME,'reg').click()
        # 定位用户名输入框并输入用户名
        self.driver.find_element(By.ID,'username').send_keys(self.username)
        # 定位邮箱输入框并输入邮箱
        self.driver.find_element(By.NAME,'email').send_keys(self.email)
        # 定位密码输入框并输入密码
        self.driver.find_element(By.NAME,'password').send_keys(self.password)
        # 定位确认密码输入框并输入密码
        self.driver.find_element(By.ID,'confirm_password').send_keys(self.password)
        # 定位同意协议并注册按钮并点击
        self.driver.find_element(By.CLASS_NAME,'signup_button').click()

    def login(self):
        # 打开网址ecshop
        self.driver.get(self.url)
        # 定位登录按钮并点击
        self.driver.find_element(By.CLASS_NAME,'sign').click()
        # 定位用户名输入框并输入用户名
        self.driver.find_element(By.NAME, 'username').send_keys(self.username)
         # 定位密码输入框并输入密码
        self.driver.find_element(By.NAME, 'password').send_keys(self.password)
        # 定位记住按钮,并点击勾选
        self.driver.find_element(By.ID, 'remember').click()
        # 定位登录按钮并点击
        self.driver.find_element(By.CLASS_NAME, 'loginbtn').click()


    def quit(self,seconds=3):
        time.sleep(seconds)
        self.driver.quit()


bro = Browser()
# bro.home_search()
bro.register()
# bro.login()
bro.quit()